package tech.lq0.dreamaticvoyage.client.render.entity;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import tech.lq0.dreamaticvoyage.Utils;
import tech.lq0.dreamaticvoyage.client.models.entity.FukamizuFishModel;
import tech.lq0.dreamaticvoyage.entity.FukamizuFishEntity;

@OnlyIn(Dist.CLIENT)
public class FukamizuFishEntityRenderer extends MobRenderer<FukamizuFishEntity, FukamizuFishModel<FukamizuFishEntity>> {

    private static final ResourceLocation TEXTURE = Utils.loc("textures/entity/fukamizu_fish.png");

    public FukamizuFishEntityRenderer(EntityRendererProvider.Context context) {
        super(context, new FukamizuFishModel<>(context.bakeLayer(FukamizuFishModel.LAYER_LOCATION)), 0.4F);
    }

    @Override
    public ResourceLocation getTextureLocation(FukamizuFishEntity pEntity) {
        return TEXTURE;
    }

    @Override
    protected void setupRotations(FukamizuFishEntity pEntityLiving, PoseStack pPoseStack, float pAgeInTicks, float pRotationYaw, float pPartialTicks) {
        super.setupRotations(pEntityLiving, pPoseStack, pAgeInTicks, pRotationYaw, pPartialTicks);
        float f = 1.0F;
        float f1 = 1.0F;
        if (!pEntityLiving.isInWater()) {
            f = 1.3F;
            f1 = 1.7F;
        }

        float f2 = f * 4.3F * Mth.sin(f1 * 0.6F * pAgeInTicks);
        pPoseStack.mulPose(Axis.YP.rotationDegrees(f2));
        pPoseStack.translate(0.0F, -0.2F, -0.4F);
        if (!pEntityLiving.isInWater()) {
            pPoseStack.translate(0.2F, 0.1F, 0.0F);
            pPoseStack.mulPose(Axis.ZP.rotationDegrees(90.0F));
        }
    }
}
